#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <ctime>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <set>
#include <hash_map>
#include <hash_set>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cassert>
#include <utility>

using namespace std;
using namespace stdext;

#define EPS 1E-8

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forv(i, a) for (int i = 0; i < int(a.size()); i++)
#define fors(i, a) for (int i = 0; i < int(a.length()); i++)
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define VI vector<int>
#define VS vector<string>

#define norm(a) sort(all(a)); a.erase(unique(all(a)), a.end());
#define num(a, v) (int)(lower_bound(all(a), v) - a.begin())

#define C_IN_FILE "input.txt"
#define C_OUT_FILE "output.txt"

string inpf = "testdata/output%s.txt";
string numf = "testdata/description/%s.ben";
string outf = "testdata/output%s.int";
string name;
FILE* f;

int n;
char line[1 << 20];

void outdata() {
}

void solve() {
}

void readdata() {
    time_t start = clock();
    vector<vector<int> > a;
    map<vector<bool>, int> nums;
    a.clear();
    nums.clear();
    char fname[100], tmp[100];
    sprintf(fname, numf.c_str(), name.c_str());
    f = fopen(fname, "rt");
    forn(i, 6) fscanf(f, "%s", tmp);
    fscanf(f, "%d", &n);
    fclose(f);
    sprintf(fname, inpf.c_str(), name.c_str());
    f = fopen(fname, "rt");
    while (fscanf(f, "%s", line) == 1) {
        int len = strlen(line);
        if (len < 2) break;
        vector<bool> tmp;
        int ka = 0;
        vector<int> cline;
        for(int i = 2; i < len; ++i) {
            bool x = line[i] == '1';
            ka++;
            tmp.pb(x);
            if (ka == n) {
                int num;
                if (nums.count(tmp) == 0) {
                    num = (int)nums.size();
                    nums[tmp] = num;
                } else {
                    num = nums[tmp];
                }
                cline.pb(num);
                tmp.clear();
                ka = 0;
            }
        }
        a.pb(cline);
    }
    fclose(f);
    sprintf(fname, outf.c_str(), name.c_str());
    f = fopen(fname, "wt");
    fprintf(f, "%d %d\n", a.size(), a[0].size());
    forv(i, a) {
        forv(j, a[i]) {
            if (j > 0) fprintf(f, " ");
            fprintf(f, "%d", a[i][j]);
        }
        fprintf(f, "\n");
    }
    fclose(f);
    cerr << clock() - start << endl;
}

int main(int argc, char* argv[]) {
    if (argc < 2) {
        cerr << "usage:\n\t" << argv[0] << " scheme_names" << endl;
    }
    for(int i = 1; i < argc; ++i) {
        name = argv[i];
        cerr << name << endl;
        readdata();
        solve();
        outdata();
    }
    return 0;
}
